<?php	
	class Connection
	{
		protected $host_name;
		protected $user_name;
		protected $pass_word;
		protected $database_name;
		protected $database_status;
		protected $connection_status;
		protected $connection;
		protected $charset;
		
		public function __construct()
		{
			$this->setHostName(HOST_NAME);
			$this->setUserName(USER_NAME);
			$this->setPassWord(PASS_WORD);
			$this->setDataBase(DATABASE);
			$this->setCharset(CHARSET);
			$this->connection_status=false;
			$this->connection=null;
			$this->database_status=false;
		}
		
		public function setHostName($host_name=null)
		{
			$this->host_name=$host_name;
		}
		
		public function getHostName()
		{
			return $this->host_name;
		}
		
		public function setUserName($user_name=null)
		{
			$this->user_name=$user_name;
		}
		
		public function getUserName()
		{
			return $this->user_name;
		}
		
		public function setPassWord($pass_word)
		{
			$this->pass_word=$pass_word;
		}
		
		public function getPassWord()
		{
			return $this->pass_word;
		}
		
		public function setDataBase($database_name)
		{
			$this->database_name=$database_name;
		}
		
		public function getDataBase()
		{
			return $this->database_name;
		}
		
		public function setDataBaseStatus($database_status)
		{
			$this->database_status=$database_status;
		}
		
		public function getDataBaseStatus()
		{
			return $this->database_status;
		}
		
		public function setConnectionStatus($connection_status)
		{
			$this->connection_status=$connection_status;
		}
		
		public function getConnectionStatus()
		{
			return $this->connection_status;
		}
		
		public function setConnection($connection)
		{
			$this->connection=$connection;
		}
		
		public function getConnection()
		{
			return $this->connection;
		}
		
		public function setCharset($charset)
		{
			$this->charset=$charset;
		}
		
		public function getCharset()
		{
			return $this->charset;
		}
		
		public function Open($info=null)
		{
			if($info!=null && is_array($info))
			{
				$this->setHostName($info['host_name']);
				$this->setUserName($info['user_name']);
				$this->setPassWord($info['pass_word']);
			}
			if(!$this->getConnectionStatus())
			{
				//if()
				$connect = mysql_pconnect($this->getHostName(), $this->getUserName(), $this->getPassWord()) or die('Không thể thiết lập kết nối với CSDL!');
				$this->setConnection($connect);
				$this->setConnectionStatus(true);
			}
			return $this->getConnection();
		}
		
		public function Close()
		{
			mysql_close();
			$this->setConnection(null);
			$this->setConnectionStatus(false);
			$this->setDataBaseStatus(false);
		}
		
		public function ConnectDB($data_name=null)
		{
			if(!$this->getConnectionStatus())
			{
				$this->Open();
			}
			mysql_select_db($this->getDataBase());
			mysql_query('Set Names "'.$this->getCharset().'"',$this->getConnection());
		}
	}
?>